﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;
using System.IO;
namespace Player
{
    public partial class shouye : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //显示评论
                PingLunSX();

                //查询评论显示
                if (Request.QueryString["gmname"]!=null)
                {
                    string gmname = Request.QueryString["gmname"].ToString();
                    List<Comments> ls = BLL.CommentsManage.SeleLikeGameNameComments(gmname);
                    if (ls.Count==0)
                    {
                        PingLunSX();
                        return;
                    }
                    this.DataList1.DataSource = ls;
                    this.DataList1.DataBind();
                }

                //评论分类
                 if (Request.QueryString["tpidcm"]!=null)
                 {
                     this.DataList1.DataSource = BLL.CommentsManage.SeleGameIdComments(Convert.ToInt32(Request.QueryString["tpidcm"]));
                     this.DataList1.DataBind();
                 }
                 

                if (Request.QueryString["id"] != null)
                {
                    int id = Convert.ToInt32(Request.QueryString["id"]);
                    this.remeng_item.DataSource = BLL.GameManage.SeleTypeIdGame(id);
                    this.remeng_item.DataBind();
                    return;
                }
                //显示热门游戏
                this.remeng_item.DataSource = BLL.GameManage.SeleTopshiGame();
                this.remeng_item.DataBind();

                
            }
            
        }

        private void PingLunSX()
        {
            this.DataList1.DataSource = BLL.CommentsManage.SeleAllComments();
            this.DataList1.DataBind();
        }

        protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btn_fb_Click(object sender, EventArgs e)
        {
            if (FileUpload.HasFile)
            {
                //获取发布内容
                //用户ID
                if (Session["usid"]==null)
                {
                    return;
                }
                int id = Convert.ToInt32(Session["usid"]);
                //游戏名称
                string title = this.txt_title.Text.Trim();
                //获取上传的文件名
                string fileName = FileUpload.FileName;
                //获取上传文件的后缀名
                string fileFix = Path.GetExtension(fileName).ToLower();
                //内容
                string desc = this.txt_desc.Text.Trim();
                if (fileFix == ".png" || fileFix == ".jpeg" || fileFix == ".jpg" || fileFix==".pic")
                {
                    FileUpload.SaveAs(Server.MapPath("../Player图片/首页用户评论图片/" + fileName));
                    this.ImaPic.ImageUrl = "~/Player/首页用户发布图片/" + fileName;
                    //游戏ID
                    List<Game> ls = BLL.GameManage.SeleNameLikeGame(title);
                    int gameid = ls[0].Gm_Id;
                    //日期
                    DateTime time = Convert.ToDateTime(DateTime.Now.ToLocalTime().ToString());
                    Comments com = new Comments();
                    com.Cm_UsId = id;
                    com.Cm_Title = title;
                    com.Cm_Image = fileName;
                    com.Cm_GmId = gameid;
                    com.Cm_Desc = desc;
                    com.Cm_Date = time;
                    bool pd = BLL.CommentsManage.AddimgComments(com);
                    if (pd)
                    {
                        //发布成功；
                        PingLunSX();
                    }
                }
            }
            else
            {
                this.lblMeassge.Text = "抱歉，您上传的不是图片类型上传失败！";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            this.Panel1.Visible = true;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            this.Panel1.Visible = false;
        }
    }
}